package pta;/**
 * @author： li
 * @date： 2022-04-01 19:50
 * @version 1.0
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class 点赞 {
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    public static void main(String[] args) throws IOException {
        Scanner sc= new Scanner(System.in);
        int [] a =new int[1001];
        int n=Integer.parseInt(in.readLine());
        int flag=0;
        while(n>0){
            String[] b = in.readLine().split(" ");
            int x =Integer.parseInt(b[0]);
            for(int i=1;i<=x;i++){
                int y =Integer.parseInt(b[i]);
                a[y]++;
                if(a[y]>a[flag])
                    flag=y;
                if(a[y]==a[flag]){
                    if(y>flag)
                        flag=y;
                }
            }
            n--;
        }
        System.out.println(flag+" "+a[flag]);
    }
}
